package com.sakura.二分查找;

public class Code69_X的平方根 {

    public static void main(String[] args) {
        int maxValue = Integer.MAX_VALUE;
        System.out.println(Math.pow(maxValue, 0.5));
    }

    public int mySqrt(int x) {
        int left = 0;
        int right = Math.min(x, 46340) + 1;
        while (left + 1 < right) {
            int mid = (right + left) >>> 1;
            if (mid * mid <= x) {
                left = mid;
            } else {
                right = mid;
            }
        }
        return left;
    }
}
